extends Control

func _ready() -> void:
	visible = false

var just_paused = false

func _process(delta: float) -> void:
	if Input.is_action_just_pressed("ui_cancel") and get_tree().paused == false:
			pause_game()
			
	elif Input.is_action_just_pressed("ui_cancel") and just_paused == false:
		unpause_game()
	just_paused = false


func unpause_game() -> void:
	get_tree().paused = false
	visible = false

func pause_game():
	visible = true
	just_paused = true
	get_tree().paused = true
	

func _on_restart_button_pressed() -> void:
	get_tree().paused = false
	GameManager.save_score()
	GameManager.load_level(GameManager.last_level_path)

func _on_resume_button_pressed() -> void:
	unpause_game()



func _on_back_button_pressed() -> void:
	get_tree().paused = false
	GameManager.save_score()
	get_tree().change_scene_to_file("res://src/UI/LevelSelectionScreen.tscn")



func _on_quit_button_pressed() -> void:
	get_tree().paused = false
	get_tree().change_scene_to_file("res://src/UI/MainMenuScreen.tscn")
